package com.p2p.account.dao.impl;

import com.p2p.account.dao.AgentLogDao;
import com.p2p.account.dao.OnlineDao;
import com.p2p.account.po.AgentLog;
import com.p2p.account.po.Online;
import com.p2p.account.vo.AgentLogCondition;
import com.p2p.account.vo.AgentLogResult;
import com.p2p.common.utils.DateUtil;
import com.p2p.common.utils.StringUtils;
import com.p2p.terminal.vo.TerminalData;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Repository
public class OnlineDaoImpl implements OnlineDao {

	private static final Logger logger = LoggerFactory.getLogger(OnlineDaoImpl.class);

	@Resource
	private JdbcTemplate jdbcTemplate;

	@Override
	public List<Online> selectOnlineDao() {

		Date date = new Date();
		SimpleDateFormat SimpleDateFormat = DateUtil.FORMAT_DATE_TIME2;
		String endTime = SimpleDateFormat.format(date);

		RowMapper<Online> rowMapper = new BeanPropertyRowMapper<>(Online.class);

		String startTime = SimpleDateFormat.format(new Date().getTime() - 3600000);

		String tablename = "p2p_online_" + startTime.substring(0, 7).replace("-", "");

		String sql = "select * from " + tablename + " where date_time  BETWEEN ? AND ? ";

	List<Online> result = jdbcTemplate.query(sql, rowMapper, startTime, endTime);
	
	
		return result;
	}
}
